<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.18"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>HElib: /HElib/src/keySwitching.cpp File Reference</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
		<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,100;1,700&family=Merriweather&family=Merriweather+Sans&family=Open+Sans&family=Poppins:ital@1&family=Roboto:ital,wght@0,400;1,300;1,900&display=swap" rel="stylesheet"> 
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body style="font-family: 'Merriweather', serif;">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand">HElib Implementing Homomorphic Encryption</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#namespaces">Namespaces</a> &#124;
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">keySwitching.cpp File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>A few strategies for generating key-switching matrices.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;unordered_set&gt;</code><br />
<code>#include &lt;NTL/ZZ.h&gt;</code><br />
<code>#include &lt;<a class="el" href="permutations_8h_source.html">helib/permutations.h</a>&gt;</code><br />
<code>#include &lt;<a class="el" href="binio_8h_source.html">helib/binio.h</a>&gt;</code><br />
<code>#include &lt;<a class="el" href="key_switching_8h_source.html">helib/keySwitching.h</a>&gt;</code><br />
<code>#include &lt;<a class="el" href="keys_8h_source.html">helib/keys.h</a>&gt;</code><br />
<code>#include &lt;<a class="el" href="api_attributes_8h_source.html">helib/apiAttributes.h</a>&gt;</code><br />
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:namespacehelib"><td class="memItemLeft" align="right" valign="top"> &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html">helib</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ad1e62bfb6af337a49d07244385b05fa0"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="key_switching_8cpp.html#ad1e62bfb6af337a49d07244385b05fa0">computeParams</a>(context,  m,  i)</td></tr>
<tr class="separator:ad1e62bfb6af337a49d07244385b05fa0"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ae5b3ba4659fee95212891f530d1a88c1"><td class="memItemLeft" align="right" valign="top">std::ostream &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#ae5b3ba4659fee95212891f530d1a88c1">helib::operator&lt;&lt;</a> (std::ostream &amp;str, const KeySwitch &amp;matrix)</td></tr>
<tr class="separator:ae5b3ba4659fee95212891f530d1a88c1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr><td colspan="2"><div class="groupHeader">Strategies for generating key-switching matrices</div></td></tr>
<tr><td colspan="2"><div class="groupText"><p>These functions are implemented in KeySwitching.cpp </p>
</div></td></tr>
<tr class="memitem:a4fb58a793bef4befd9d75d8852d8fc55"><td class="memItemLeft" align="right" valign="top">long&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a4fb58a793bef4befd9d75d8852d8fc55">helib::KSGiantStepSize</a> (long D)</td></tr>
<tr class="memdesc:a4fb58a793bef4befd9d75d8852d8fc55"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function that returns number of baby steps. Used to keep this and matmul routines "in sync".  <a href="namespacehelib.html#a4fb58a793bef4befd9d75d8852d8fc55">More...</a><br /></td></tr>
<tr class="separator:a4fb58a793bef4befd9d75d8852d8fc55"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4da7a89f85244e58f456a86832c46a27"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a4da7a89f85244e58f456a86832c46a27">helib::addAllMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="memdesc:a4da7a89f85244e58f456a86832c46a27"><td class="mdescLeft">&#160;</td><td class="mdescRight">Maximalistic approach: generate matrices s(X^e)-&gt;s(X) for all e in Zm*.  <a href="namespacehelib.html#a4da7a89f85244e58f456a86832c46a27">More...</a><br /></td></tr>
<tr class="separator:a4da7a89f85244e58f456a86832c46a27"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3ace8477657e91faeb4c33824bab098d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a3ace8477657e91faeb4c33824bab098d">helib::addSome1DMatrices</a> (SecKey &amp;sKey, long bound=<a class="el" href="key_switching_8h.html#a3838902c58164cdb58bee2043b2263bd">HELIB_KEYSWITCH_THRESH</a>, long keyID=0)</td></tr>
<tr class="memdesc:a3ace8477657e91faeb4c33824bab098d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Generate some matrices of the form s(X^{g^i})-&gt;s(X), but not all. For a generator g whose order is larger than bound, generate only enough matrices for the giant-step/baby-step procedures (2*sqrt(ord(g))of them).  <a href="namespacehelib.html#a3ace8477657e91faeb4c33824bab098d">More...</a><br /></td></tr>
<tr class="separator:a3ace8477657e91faeb4c33824bab098d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8f3689b135fde2c843eed5ce0813a975"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a8f3689b135fde2c843eed5ce0813a975">helib::add1DMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="memdesc:a8f3689b135fde2c843eed5ce0813a975"><td class="mdescLeft">&#160;</td><td class="mdescRight">Generate all matrices s(X^{g^i})-&gt;s(X) for generators g of Zm* /(p) and i&lt;ord(g). If g has different orders in Zm* and Zm* /(p) then generate also matrices of the form s(X^{g^{-i}})-&gt;s(X)  <a href="namespacehelib.html#a8f3689b135fde2c843eed5ce0813a975">More...</a><br /></td></tr>
<tr class="separator:a8f3689b135fde2c843eed5ce0813a975"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a63d75eed1d12814e2e858ab82e07d311"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a63d75eed1d12814e2e858ab82e07d311">helib::addBSGS1DMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="separator:a63d75eed1d12814e2e858ab82e07d311"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a40b42a155c81c0507222ebca1f0a39f8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a40b42a155c81c0507222ebca1f0a39f8">helib::addSomeFrbMatrices</a> (SecKey &amp;sKey, long bound=<a class="el" href="key_switching_8h.html#a3838902c58164cdb58bee2043b2263bd">HELIB_KEYSWITCH_THRESH</a>, long keyID=0)</td></tr>
<tr class="memdesc:a40b42a155c81c0507222ebca1f0a39f8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Generate all/some Frobenius matrices of the form s(X^{p^i})-&gt;s(X)  <a href="namespacehelib.html#a40b42a155c81c0507222ebca1f0a39f8">More...</a><br /></td></tr>
<tr class="separator:a40b42a155c81c0507222ebca1f0a39f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a62bfda232309a69cc3824e5323345073"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a62bfda232309a69cc3824e5323345073">helib::addFrbMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="separator:a62bfda232309a69cc3824e5323345073"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af9483c8e129d827f9b49f140a327dd15"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#af9483c8e129d827f9b49f140a327dd15">helib::addBSGSFrbMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="separator:af9483c8e129d827f9b49f140a327dd15"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0c3d6b66cd30aed055d9c5a6333eca7c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a0c3d6b66cd30aed055d9c5a6333eca7c">helib::addMinimal1DMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="memdesc:a0c3d6b66cd30aed055d9c5a6333eca7c"><td class="mdescLeft">&#160;</td><td class="mdescRight">These routines just add a single matrix (or two, for bad dimensions)  <a href="namespacehelib.html#a0c3d6b66cd30aed055d9c5a6333eca7c">More...</a><br /></td></tr>
<tr class="separator:a0c3d6b66cd30aed055d9c5a6333eca7c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa94886e3afbcd49800243fd7fdaedd39"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#aa94886e3afbcd49800243fd7fdaedd39">helib::addMinimalFrbMatrices</a> (SecKey &amp;sKey, long keyID=0)</td></tr>
<tr class="separator:aa94886e3afbcd49800243fd7fdaedd39"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7d420cdf0dc5b6968a8a89809cd5b5f3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a7d420cdf0dc5b6968a8a89809cd5b5f3">helib::addMatrices4Network</a> (SecKey &amp;sKey, const PermNetwork &amp;net, long keyID=0)</td></tr>
<tr class="separator:a7d420cdf0dc5b6968a8a89809cd5b5f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a96c1092ac50c752cc8577da03cf232d4"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacehelib.html#a96c1092ac50c752cc8577da03cf232d4">helib::addTheseMatrices</a> (SecKey &amp;sKey, const std::set&lt; long &gt; &amp;automVals, long keyID=0)</td></tr>
<tr class="memdesc:a96c1092ac50c752cc8577da03cf232d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Generate specific key-switching matrices, described by the given set.  <a href="namespacehelib.html#a96c1092ac50c752cc8577da03cf232d4">More...</a><br /></td></tr>
<tr class="separator:a96c1092ac50c752cc8577da03cf232d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>A few strategies for generating key-switching matrices. </p>
<p>Copyright IBM Corporation 2012 All rights reserved. </p>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="ad1e62bfb6af337a49d07244385b05fa0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad1e62bfb6af337a49d07244385b05fa0">&#9670;&nbsp;</a></span>computeParams</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define computeParams</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">context, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">m, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">i&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line">  <span class="keywordtype">bool</span> native;                                                                 \</div>
<div class="line">  long <a class="code" href="namespacehelib.html#a8693a4a2d91babebc9b8887bbcd1f0ea">ord</a>, gi, g2md;                                                          \</div>
<div class="line">  NTL::mulmod_precon_t g2mdminv;                                               \</div>
<div class="line">  if (i == context.zMStar.numOfGens()) { <span class="comment">/* Frobenius matrices */</span>              \</div>
<div class="line">    ord = context.zMStar.getOrdP();                                            \</div>
<div class="line">    gi = context.zMStar.getP();                                                \</div>
<div class="line">    native = <span class="keyword">true</span>;                                                             \</div>
<div class="line">  } <span class="keywordflow">else</span> { <span class="comment">/* one of the &quot;regular&quot; dimensions */</span>                               \</div>
<div class="line">    ord = context.zMStar.OrderOf(i);                                           \</div>
<div class="line">    gi = context.zMStar.ZmStarGen(i);                                          \</div>
<div class="line">    native = context.zMStar.SameOrd(i);                                        \</div>
<div class="line">    if (!native) {                                                             \</div>
<div class="line">      g2md = PowerMod(gi, -<a class="code" href="namespacehelib.html#a8693a4a2d91babebc9b8887bbcd1f0ea">ord</a>, m); <span class="comment">/* g^{-ord} mod m */</span>                       \</div>
<div class="line">      g2mdminv = PrepMulModPrecon(g2md, m);                                    \</div>
<div class="line">    }                                                                          \</div>
<div class="line">  }                                                                            \</div>
<div class="line">  NTL::mulmod_precon_t giminv = PrepMulModPrecon(gi, m);</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
<div class="ttc" id="anamespacehelib_html_a8693a4a2d91babebc9b8887bbcd1f0ea"><div class="ttname"><a href="namespacehelib.html#a8693a4a2d91babebc9b8887bbcd1f0ea">helib::ord</a></div><div class="ttdeci">long ord(long N, long p)</div><div class="ttdoc">Compute the highest power of p that divides N.</div><div class="ttdef"><b>Definition:</b> NumbTh.cpp:695</div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
        <script type="text/javascript" src="doxy-boot.js"></script>
</html>
